export function useWebSocket(handleMessage) {
    let ws = new WebSocket("ws://192.168.1.104:8080/api/ws/1");

    const init = () => {
        // console.log("加载WebSocket")
        bindEvent();
    }

    function bindEvent() {
        ws.addEventListener('open', handleOpen, false);
        ws.addEventListener('close', handleColse, false);
        ws.addEventListener('error', handleError, false);
        ws.addEventListener('message', handleMessage, false);
    }

    function handleOpen(e) {
        console.log('WebSocket open', e);
    }

    function handleColse(e) {
        console.log('WebSoket close', e);
    }

    function handleError(e) {
        console.log('WebSoket close', e);
    }
    init();

    return ws;
}